angular.module('drag', []).
    directive('draggable', function ($document) {
        var startX = 0, startY = 0, x = 0, y = 0;
        return function (scope, element, attr) {
            element.css({
                position: 'relative',
                border: '1px solid red',
                backgroundColor: 'lightgrey',
                cursor: 'pointer'
            });
            element.bind('mousedown', function (event) {
                startX = event.screenX - x;
                startY = event.screenY - y;
                $document.bind('mousemove', mousemove);
                $document.bind('mouseup', mouseup);
            });
            function mousemove(event) {
                y = event.screenY - startY;
                x = event.screenX - startX;
                element.css({
                    top: y + 'px',
                    left: x + 'px'
                });
            }

            function mouseup() {
                $document.unbind('mousemove', mousemove);
                $document.unbind('mouseup', mouseup);
            }
        }
    });

function test(){
    operation1().then(function (result1) {
        return operation2(result1)
    }).then(function (result2) {
            return operation3(result2);
        }).then(function (result3) {
            return operation4(result3);
        }).then(function (result4) {
            return operation5(result4)
        }).then(function (result5) {
            //And so on
        });
}